﻿using MultiChoiceVoting.Helpers;
using MultiChoiceVoting.Models;
using MultiChoiceVoting.Services;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Environment;

namespace MultiChoiceVoting.Handlers
{
    public class MultiChoiceQuestionHandler : ContentHandler
    {
        public MultiChoiceQuestionHandler(IRepository<MultiChoiceVotingPartRecord> repository)
        {
            Filters.Add(StorageFilter.For(repository));

            OnActivated<MultiChoiceVotingPart>((context, part) => part.AnswersField.Loader(
                () => AnswerSerializerHelper.DeserializeAnswerList(part.SerializedAnswers)));
        }
    }
}